package com.example.disinfestation.controller;


import com.example.disinfestation.entity.Pest;
import com.example.disinfestation.entity.Pservices;
import com.example.disinfestation.entity.Pservicesimg;
import com.example.disinfestation.mapper.PservicesimgMapper;
import com.example.disinfestation.service.PservicesService;
import com.example.disinfestation.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class PservicesController extends BaseController{

    @Autowired
    PservicesService pservicesService;
    @Autowired
    PservicesimgMapper pservicesimgMapper;



    @RequestMapping("selectAllPservices")
    @ResponseBody
    public JsonResult<List<Pservices>> selectAll(){
        JsonResult result = new JsonResult();
        System.err.println("查询提供的所有服务");
        try {
            List<Pservices> data = pservicesService.selectAllPservices();

            result.setState(SUCCESS);
            result.setData(data);
        }catch (Exception e){
            result.setMessage("出现异常");
        }
        return result;
    }


    @RequestMapping("selectPservicesById")
    @ResponseBody
    public JsonResult<Pservices> selectPservicesById(Integer id){
        JsonResult result = new JsonResult();
        System.err.println("根据id查询提供的服务");
        try {
            Pservices data = pservicesService.selectPservicesById(id);
            List<Pservicesimg> data1 = pservicesimgMapper.selectPhotoById(id);

            result.setState(SUCCESS);
            result.setData(data);
            result.setData1(data1);
        }catch (Exception e){
            result.setMessage("出现异常");
        }
        return result;
    }


}
